package com.douyin.controller;

import com.douyin.common.Result;
import com.douyin.service.DouyinParseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Slf4j
@RestController
@RequestMapping("/health")
public class HealthController {

    @Autowired
    private DouyinParseService parseService;

    @GetMapping
    public Result<?> health() {
        Map<String, Object> status = new HashMap<>();
        status.put("status", "UP");
        status.put("timestamp", System.currentTimeMillis());
        status.put("application", "douyin-parser-backend");
        return Result.success("服务正常", status);
    }
    
    @PostMapping("/test-parse")
    public Result<Object> testParse(@RequestBody Map<String, String> request) {
        try {
            String shareText = request.get("shareText");
            if (shareText == null || shareText.trim().isEmpty()) {
                return Result.error("分享内容不能为空");
            }

            log.info("临时测试解析: {}", shareText);
            
            // 直接调用解析服务
            Map<String, Object> result = parseService.parseDouyinUrl(shareText);
            
            return Result.success(result);
            
        } catch (Exception e) {
            log.error("临时测试解析失败: {}", e.getMessage(), e);
            return Result.error("解析失败: " + e.getMessage());
        }
    }
}